﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DevExpress.XtraGrid.Views.Grid;

namespace QuanLyKho.BanHang
{
    public partial class DanhSachSPTrongCuaHang : UserControl
    {
        public DanhSachSPTrongCuaHang()
        {
            InitializeComponent();
            LoadData();
        }

        public void LoadData()
        {
            var table = DataAll.SelectAll("[SanPhamTrongCuaHang]",
                "TenCuaHang, SUM(SoLuong) AS 'TongSoLuong'", " GROUP BY  TenCuaHang");
            gridCuaHang.DataSource = table;
            SetPropertiesGrid();
        }

        public void SetPropertiesGrid()
        {
            //gvChiaHang.BestFitColumns();
            gvCuaHang.OptionsBehavior.Editable = false;
            gvCuaHang.FocusRectStyle = DrawFocusRectStyle.RowFullFocus;
            gvCuaHang.OptionsSelection.EnableAppearanceFocusedCell = false;
            gvCuaHang.OptionsSelection.MultiSelect = true;
            gvCuaHang.OptionsView.ShowGroupPanel = false;
            gvCuaHang.OptionsView.ColumnAutoWidth = true;
            gvCuaHang.OptionsView.ShowFooter = true;
            gvCuaHang.OptionsFind.AlwaysVisible = true;
            gvCuaHang.Columns["ID"].Visible = false;
        }

        private void gvCuaHang_DoubleClick(object sender, EventArgs e)
        {
            if (gvCuaHang.FocusedRowHandle >= 0)
            {
                DanhSachSPCuaCuaHang.CuaHang = gvCuaHang.GetDataRow(gvCuaHang.FocusedRowHandle)["TenCuaHang"].ToString();
                DanhSachSPCuaCuaHang.Loai = true;
                var themsp = new DanhSachSPCuaCuaHang();
                themsp.ShowDialog();
                LoadData();
                DanhSachSPCuaCuaHang.CuaHang = "0";
            }
        }
    }
}
